<!DOCTYPE html>
<html>

<head lang="en">
    <title>找攻略</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategy.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="js/plugins/dialog2/dialog.css">
    <script src="js/plugins/dialog2/dialog.min.js"></script>


    <script>

        $(function () {
            //查询推荐的地区-----页签地区的显示
            $.get("/regions/1", function (data) {
                //把推荐地区的数据拼接好
                var html = "";
                //每个页签显示内容的关联
                var content = "";
                $.each(data, function (index, ele) {
                    html += '<li class="nav-item">' +
                        '<a data-id="' + ele.id + '" class="nav-link" id="pills-' + ele.id + '-tab" data-toggle="pill" href="#pills-' + ele.id + '">' + ele.name + '</a>' +
                        '</li>'
                    content += ' <div class="tab-pane fade" id="pills-'+ele.id+'"></div>'
                })
                //把拼接好的数据进行添加
                $("#pills-tab").append(html);
                $("#pills-tabContent").append(content);
            })

            var regionId;
            var currentPage;
            var totalPage;

            //<-----包含该地区当季推荐+全部攻略----->为每一个页签绑定事件发送请求
            $("#pills-tab").on("click",".nav-link",function () {
                currentPage = 2;
                totalPage = 2;
                regionId = $(this).data("id");
                console.log(regionId);
                if (regionId){
                    $.get("/regions/"+regionId+"/strategies",function (data) {
                        $("#pills-"+regionId).html(data);
                    },"html")
                }

            })

                var dataList = [];
            //推荐地区下的所有攻略分页操作
            function query(){
                    $.get("/regions/"+regionId+"/strategies", {currentPage: currentPage, pageSize: 6}, function (data) {
                        currentPage += 1;
                        totalPage = data.pages;
                        console.log(data);
                        //把获取的数据拼接好
                        var html = "";
                        $.each(data.list,function (index,item) {
                        html+='<div class="col-6 mb">'+
                                '<a href="../strategyCatalogs.html?id='+item.id+'">'+
                                '<img class="float-left " src="'+item.coverUrl+'">'+
                                '<div class="classify-text">'+
                                '<span>'+item.subTitle+'</span>'+
                                '<p>0人收藏</p>'+
                                '</div>'+
                            '</a>'+
                            '</div>'
                        })
                        $(".classify").append(html);
                    })
                }

                //屏幕滚动判断+翻页
                $(window).scroll(function () {
                    if ($(window).height() + $(window).scrollTop() >= $(document).height()) {
                        if (currentPage <= totalPage) {
                            query();
                        } else {
                            $(document).dialog({
                                type : 'notice',
                                infoText: '我是个有底线的人!',
                                autoClose: 2500,
                                position: 'bottom'  // center: 居中; bottom: 底部
                            });
                        }
                    }

                })


            //攻略游记推荐
            $.get("/travels/commend", {"type": 3, "pageSize": 3}, function (data) {
                /*console.log(data);*/
                $("#loorId").renderValues(data, {
                    setHref: function (ele, val) {
                        /*console.log(val);
                        console.log($(ele).attr("href"));
                        var href = $(ele).attr("href") + val;*/
                        $(ele).attr("href", $(ele).attr("href") + val);
                    }
                })
                $(".carousel-item:first").addClass("active")
            })

            //当季推荐查询
            $.get("/strategies", {"state": 2}, function (data) {
                console.log(data);
                $(".strategyCommend").renderValues(data, {
                    setHref: function (ele, val) {
                        $(ele).attr("href", $(ele).attr("href") + val);
                    }
                })
            })

        })

    </script>


</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="找攻略">
            </div>
        </div>
    </div>
</div>


<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab" role="tablist">
    <li class="nav-item">
        <a class="nav-link active show" id="pills-top-tab" data-toggle="pill" href="#pills-top">
            <span style="font-weight: bold;">推荐</span>
        </a>
    </li>
</ul>


<div class="tab-content" id="pills-tabContent">
    <div class="tab-pane fade active show" id="pills-top">


        <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
            <div id="travelsCommends">
                <!--周推荐数据渲染-->
                <div id="loorId" class="carousel-inner">
                    <div render-loop="list">
                        <div class="carousel-item">
                            <div class="container commend">
                                <div>
                                    <a href="/travelContent.html?id=" render-fun="setHref" render-key="list.TravelId">
                                        <img render-src="list.commendCoverUrl">
                                        <p render-html="list.commendTitle"></p>
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
                <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                <span class="sr-only"></span>
            </a>
            <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
                <span class="carousel-control-next-icon" aria-hidden="true"></span>
                <span class="sr-only"></span>
            </a>
        </div>

        <hr>

        <div class="container strategyCommend">
            <h6>当季推荐</h6>
            <div class="row hot" render-loop="list">
                <div class="col-4">
                    <a href="strategyCatalogs.html?id=" render-fun="setHref" render-key="list.id">
                        <img render-src="list.coverUrl">
                        <p render-html="list.title"></p>
                    </a>
                </div>
            </div>
        </div>

    </div>
</div>







</body>

</html>